package com.autoEcole.service.util;

import com.autoEcole.dao.util.DAOFactoryMaker;
import com.autoEcole.service.CoursService;
import com.autoEcole.service.DatePermisService;
import com.autoEcole.service.DocumentService;
import com.autoEcole.service.EleveService;
import com.autoEcole.service.EleveExamenService;
import com.autoEcole.service.EmployeeService;
import com.autoEcole.service.EtatService;
import com.autoEcole.service.ExamenService;
import com.autoEcole.service.ExaminateurService;
import com.autoEcole.service.FonctionService;
import com.autoEcole.service.LeconService;
import com.autoEcole.service.PermisService;
import com.autoEcole.service.ResultatService;
import com.autoEcole.service.VehiculeService;
import com.autoEcole.service.util.ServiceFactory;
import com.constant.GeneralConstants;

public class ServiceFactory implements AbstractServiceFactory {
	/**
	 * AbstractServiceFactory instance
	 */
	private static ServiceFactory factory;

	/**
	 * Non instantiable constructor.
	 * 
	 */
	private ServiceFactory() {
		// Non instantiable constructor.
	}

	/**
	 * This method implements a Singleton wich allows to construct the unique
	 * instance of the class <code>ServiceFactory</code>.
	 * 
	 * @return the unique instance of the class <code>ServiceFactory</code>.
	 */
	public static synchronized ServiceFactory getInstance() {
		if (factory == null)
			factory = new ServiceFactory();
		return factory;
	}
	
	public CoursService getCoursService() {
		CoursService coursService = CoursService.getInstance();
		coursService.setCoursDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getCoursDAO());
		return coursService;
	}

	public DatePermisService getDatePermisService() {
		DatePermisService datePermisService = DatePermisService.getInstance();
		datePermisService.setDatePermisDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getDatePermisDAO());
		datePermisService.setEleveDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getEleveDAO());
		datePermisService.setPermisDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getPermisDAO());
		datePermisService.setEtatDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getEtatDAO());
		return datePermisService;
	}
	
	public DocumentService getDocumentService() {
		DocumentService documentService = DocumentService.getInstance();
		documentService.setDocumentDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getDocumentDAO());
		return documentService;
	}
	
	public EleveService getEleveService() {
		EleveService eleveService = EleveService.getInstance();
		eleveService.setEleveDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getEleveDAO());
		return eleveService;
	}
	
	public EleveExamenService getEleveExamenService() {
		EleveExamenService eleveExamenService = EleveExamenService.getInstance();
		eleveExamenService.setEleveExamenDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getEleveExamenDAO());
		eleveExamenService.setCoursDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getCoursDAO());
		eleveExamenService.setEleveDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getEleveDAO());
		eleveExamenService.setExamenDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getExamenDAO());
		eleveExamenService.setPermisDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getPermisDAO());
		eleveExamenService.setResultatDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getResultatDAO());
		return eleveExamenService;
	}
	
	public EmployeeService getEmployeeService() {
		EmployeeService employeeService = EmployeeService.getInstance();
		employeeService.setEmployeeDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getEmployeeDAO());
		employeeService.setFonctionDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getFonctionDAO());
		return employeeService;
	}
	
	public EtatService getEtatService() {
		EtatService etatService = EtatService.getInstance();
		etatService.setEtatDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getEtatDAO());
		return etatService;
	}
	
	public ExamenService getExamenService() {
		ExamenService examenService = ExamenService.getInstance();
		examenService.setExamenDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getExamenDAO());
		return examenService;
	}
	
	public ExaminateurService getExaminateurService() {
		ExaminateurService examinateurService = ExaminateurService.getInstance();
		examinateurService.setExaminateurDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getExaminateurDAO());
		return examinateurService;
	}
	
	public FonctionService getFonctionService() {
		FonctionService fonctionService = FonctionService.getInstance();
		fonctionService.setFonctionDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getFonctionDAO());
		return fonctionService;
	}
	
	public LeconService getLeconService() {
		LeconService leconService = LeconService.getInstance();
		leconService.setLeconDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getLeconDAO());
		return leconService;
	}
	
	public PermisService getPermisService() {
		PermisService permisService = PermisService.getInstance();
		permisService.setPermisDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getPermisDAO());
		return permisService;
	}
	
	public ResultatService getResultatService() {
		ResultatService resultatService = ResultatService.getInstance();
		resultatService.setResultatDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getResultatDAO());
		return resultatService;
	}	
	
	public VehiculeService getVehiculeService() {
		VehiculeService vehiculeService = VehiculeService.getInstance();
		vehiculeService.setVehiculeDAO(DAOFactoryMaker.getDAOFactory(GeneralConstants.MYSQL_DATABASE).getVehiculeDAO());
		return vehiculeService;
	}
}
